from typing import Any

from aiogram import types
from aiogram_dialog import DialogManager

from src.presentation.tg_bot.states import OrderDetailsSG, UserOrdersSG


async def display_order_details(call: types.CallbackQuery, widget: Any, manager: DialogManager, order_id: str):
    await manager.start(OrderDetailsSG.order_details, {"order_id": int(order_id)})


async def back_to_status_select(call: types.CallbackQuery, _, manager: DialogManager):
    await manager.switch_to(UserOrdersSG.orders_history)


async def display_orders(_, widget: Any, manager: DialogManager):
    manager.dialog_data["user_id"] = manager.start_data.get("user_id")
    manager.dialog_data["orders_status"] = widget.widget_id

    if widget.widget_id == "active":
        await manager.switch_to(UserOrdersSG.user_orders_active)
    else:
        await manager.switch_to(UserOrdersSG.user_orders_archive)


async def show_user_orders(call: types.CallbackQuery, widget: Any, dialog_manager: DialogManager):
    await dialog_manager.start(
        UserOrdersSG.orders_history,
        {"user_id": call.from_user.id, "orders_type": widget.widget_id},
    )
